import React, { Component } from 'react'
import { Switch, Route, Redirect } from 'react-router-dom'

import { getRoutes } from 'utils/getRoutes'

import Authorized from 'utils/Authorized'
import NotFound from 'container/exception/404'

const { AuthorizedRoute, check } = Authorized

export default class App extends Component {
  render () {
    const {
      match: { path },
      routerData
    } = this.props

    return (
      <Switch>
        {
          getRoutes(path, routerData).map(v => (
            <AuthorizedRoute
              key = { v.key }
              path = { v.path }
              component = { v.component }
              exact = { v.exact }
              authority = { v.auth }
              redirectPath = '/exception/403'
            />
          ))
        }
        <Route component = { NotFound } />
      </Switch>
    )
  }
}